# 给定一个已排序的链表的头 head ， 删除所有重复的元素，使每个元素只出现一次 。返回 已排序的链表 。

class ListNode(object):
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


class Solution(object):

    def deleteDuplicates(self, head: ListNode) -> ListNode:
        """
        :type head: ListNode
        :rtype: ListNode
        """
        fast = slow = head
        while fast:
            fast = fast.next
            if fast:
                if fast.val != slow.val:
                    slow = slow.next
                    slow.val = fast.val
        if slow:
            slow.next = None
        return head
